/*
day156
2020.1.31
*/ 
#include<iostream>
#include<string>
#include<unordered_map>
using namespace std;

class Solution {
public:
    int lengthOfLongestSubstring(string s) 
	{
		if(s.empty())	return 0;
        unordered_map<char,int> m;
        int begin=0,end=1,size=s.size();
        int res=1;
        m[s[0]]=1;
        while(begin<size && end<size)
        {
        	char ch_end=s[end];
        	
        	if(m[ch_end]==0)
        	{
        		m[ch_end]=1; 
        		++end;	
			}
			else
			{
				int cur_size=end-begin;
				res=res >= cur_size ? res : cur_size;
				while(begin<end && s[begin] != ch_end)
				{
					m[s[begin]]=0;
					++begin;
				}
				++begin;
				++end;
			}
		}
		
		int cur_size=end-begin;
		res=res >= cur_size ? res : cur_size;
		
		return res;
    }
};

int main()
{
	
}
